package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.customer.CustomerReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.CountShengYuVo;
import com.zzyl.vo.NursingProjectVo;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags="微信小程序端客户预约管理")
public class CustomerReservationController extends BaseController {
    @Autowired
    private CustomerReservationService customerReservationService;
    //1.查询取消预约数量
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
        Integer count = customerReservationService.getCancelledCount(userId);
        return ResponseResult.success(count);
    }

    //2. 查询每个时间段剩余预约次数
    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult<List<CountShengYuVo>> countByTime(@RequestParam Long time) {
        List<CountShengYuVo> countShengYuVos = customerReservationService.countByTime(time);
        return ResponseResult.success(countShengYuVos);
    }

    //3.新增预约
    @PostMapping()
    @ApiOperation("新增预约")
    public ResponseResult insert(@RequestBody ReservationDto reservationDto) {
         customerReservationService.insert(reservationDto);
         return ResponseResult.success();
    }

    //4.分页查询预约列表
    @GetMapping("/page")
    @ApiOperation("分页查询预约列表")
    public ResponseResult<PageResponse<ReservationVo>> selectByPage(
            @ApiParam(value = "预约状态，0：待报道，1：已完成，2：取消，3：过期")
            @RequestParam(value = "status", required = false)  //默认为true时必须要
            Integer status,

            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1")
            Integer pageNum,

            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10")
            Integer pageSize) {
        PageResponse<ReservationVo> nursingPage = customerReservationService.selectByPage(status, pageNum, pageSize);
        return ResponseResult.success(nursingPage);
    }

    //5.取消预约
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult cancle(@PathVariable("id") Long id) {
        customerReservationService.updateStatusById(id);
        return ResponseResult.success();
    }
}
